#ifndef MENU_HH_
# define MENU_HH_

# include <GL/glew.h>
# include <cassert>
# include <math/vector.hh>
# include <iostream>
# include "../../interfaces/blitable.hh"
# include "../../display/texture.hh"
# include <GL/gl.h>
# include <boost/shared_ptr.hpp>
# include "../../content-handler.hh"

// toutes les coordonnees sont en % de la fenetre
class Menu : public Blitable
{
public:
  Menu ();
  Menu (Vector2d pos, Vector2d size);

  Vector2d pos_get ()
  {
    return pos_;
  }

  Vector2d size_get ()
  {
    return size_;
  }

  void activate ()
  {
    is_active_ = true;
  }

  void desactivate ()
  {
    is_active_ = false;
  }

  virtual void set_coord (Vector2d base, Vector2d size_max)
  {
    size_max_ = size_max;

    Vector2d tmp (base (0) + pos_ (0) * size_max_ (0) / 100,
		  base (1) + pos_ (1) * size_max_ (1) / 100);
    Vector2d end (tmp (0) + size_ (0) * size_max_ (0) / 100,
		  tmp (1) + size_ (1) * size_max_ (1) / 100);
    base_ = tmp;
    end_ = end;
  }

  virtual void size_max_set (Vector2d size_max)
  {
    size_max_ = size_max;

    Vector2d base (pos_ (0) * size_max_ (0) / 100,
		   pos_ (1) * size_max_ (1) / 100);
    Vector2d end ((pos_ (0) + size_ (0)) * size_max_ (0) / 100,
		  (pos_ (0) + size_ (0)) * size_max_ (1) / 100);
    base_ = base;
    end_ = end;
  }

  virtual bool on_hoover (Vector2d cursor);
  virtual void hoover_action (Vector2d cursor) = 0;

  void on_click (Vector2d cursor, unsigned int button_id);
  virtual void click_action (Vector2d cursor, unsigned int button_id) = 0;

  void on_release (Vector2d cursor, unsigned int button_id);
  // virtual void click_action (Vector2d cursor, int button_id) = 0;

  void hoover (bool b) { hoover_ = b; }
protected:
  Vector2d size_;
  Vector2d pos_;
  bool is_active_;
  Vector2d size_max_;
  Vector2d base_;
  Vector2d end_;
  bool hoover_;

  boost::shared_ptr<Texture> tex_;
};

class Container : public Menu
{
public:
  Container ();
  Container (Vector2d pos, Vector2d size);

  ~Container ();

  void set_coord (Vector2d base, Vector2d size_max);
  void size_max_set (Vector2d size_max);

  virtual bool on_hoover (Vector2d cursor);
  void set_grid (int nb_block_x, int nb_block_y);
  bool add_menu (Menu* m);
  void hoover_action (Vector2d cursor);
  void click_action (Vector2d cursor, unsigned int button_id);
  void dispatch () const;
protected:
  Menu*** grid_;
  int nb_x;
  int nb_y;
};

class Button : public Menu
{
public:
  Button ();
  Button (Vector2d pos, Vector2d size);

  ~Button ();

  void hoover_action (Vector2d cursor);
  void click_action (Vector2d cursor, unsigned int button_id);
  void dispatch () const;

protected:
  int data_;
};
#endif /// !MENU_HH_
